/*
	Class: DocElemAlt
	
		This class handles the <alt /> tag. This tag provides content for the
		conversion to a non-Frontal language like HTML.
		
		If the alt tag has an id then it is meant to provide replacement content
		for some other element. That other element should refer to the alt
		element via an altId attribute.
		
		An alternative to this is the altContent attribute which will replace 
		whatever tag has it with the attribute's value in the conversion 
		process. (Note that with this approach it is not possible to set a 
		target and so it is up to the converter to decide if it is relevant or
		not. See the "target" attribute below.)
		
		If the alt tag does not have an id, then it is meant to provide
		additional content to be inserted at the tag's location.
		
		The "target" attribute is used to control when the alt tag will be used
		in a conversion process. If it is empy or not defined then it is always 
		used otherwise it must be a space-separated list of values. Currently,
		the only understood value is "html." 
*/
package com.frontalcode 
{
	/**
	 * The DocElemAlt class handles the <alt /> tag.
	 */
    public class DocElemAlt extends DocumentElement
    {
		/**
		 * Creates a new DocElemAlt instance.
		 * 
		 * @param document	The document this element belongs to.
		 * @param parent	The element's parent in the document tree.
		 * @param node		The XML node this element is associated with.
		 * @param options	Options affecting the behavior of this instance.
		 * 					(This object does not have built-in support for any
		 * 					options.)
		 */
		public function DocElemAlt ( document : Document, parent : DocumentElement, node : XML, options : Object = null )
		{
			super ( document, parent, node, options );
			
			processesOwnContent = true;
		}
		
		/**
		 * @private
		 */
		override public function toXMLString ( options : Object = null ) : String 
		{                                              
			if ( options == null ) options = { };
				
			if ( ! options.includeAlt && ( options.isSEOProcess || options.target != null ) )
			{
				if ( attributeExists ( "id" ) ) return "";
			
				if ( attributeExists ( "target" ) )
				{
					var targets : Array = getAttribute ( "target" ).split ( /\s+/ );
					if ( ! ( ( options.isSEOProcess && targets.indexOf ( "html" ) >= 0 ) || targets.indexOf ( options.target ) >= 0 ) ) return "";
				}
			}
			
			return node.text ( ).toString ( );
		}
	}
}
